package fleditor.core.iso
{
	import flash.display.Sprite;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	
	public class IsoDisplayObject extends Sprite
	{
		protected var _position:IsoPoint;
		private var _size:Number;
		protected var _vx:Number = 0;
		protected var _vy:Number = 0;
		protected var _vz:Number = 0;
		
		public static const Y_CORRECT:Number = Math.cos(-Math.PI / 6) * Math.SQRT2;
		
		public function IsoDisplayObject()
		{
			_position = new IsoPoint();
			updateScreenPosition();
		}
		
		protected function updateScreenPosition():void
		{
			var screenPos:Point = IsoUtils.spaceToScreen(_position);
			super.x = screenPos.x;
			super.y = screenPos.y;
		}
		
		override public function set x(value:Number):void
		{
			_position.x = value;
			updateScreenPosition();
		}
		
		override public function get x():Number
		{
			return _position.x;
		}
		
		override public function set y(value:Number):void
		{
			_position.y = value;
			updateScreenPosition();
		}
		
		override public function get y():Number
		{
			return _position.y;
		}
		
		override public function set z(value:Number):void
		{
			_position.z = value;
			updateScreenPosition();
		}
		
		override public function get z():Number
		{
			return _position.z;
		}
		
		public function set position(value:IsoPoint):void
		{
			_position = value;
			updateScreenPosition();
		}
		
		public function get position():IsoPoint
		{
			return _position;
		}
		
		public function get depth():Number
		{
			return (_position.x + _position.z) * .866 - _position.y * .707;
		}
		
		public function get size():Number
		{
			return _size;
		}
		
		public function get rect():Rectangle
		{
			return new Rectangle(x - _size / 2, z - _size / 2, _size, _size);
		}
		
		public function set vx(value:Number):void
		{
			_vx = value;
		}
		
		public function get vx():Number
		{
			return _vx;
		}
		
		public function set vy(value:Number):void
		{
			_vy = value;
		}
		
		public function get vy():Number
		{
			return _vy;
		}
		
		public function set vz(value:Number):void
		{
			_vz = value;
		}
		
		public function get vz():Number
		{
			return _vz;
		}
		
		public function set size(value:Number):void
		{
			_size = value;
		}
		
		public function setScreenPoint(point:Point):void
		{
			super.x=point.x;
			super.y=point.y;
		}
		
		public function getScreenPoint():Point
		{
			return new Point(super.x, super.y);
		}
		
		public function dispose():void
		{
			if(parent) parent.removeChild(this);
			_position=null;
		}
	}
}